package cn.qayy.dto;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;

import cn.qayy.constants.CollectionConstant;
import cn.qayy.constants.Constant;
import cn.qayy.service.IPolicyService;
import cn.qayy.service.Uploadable;
import cn.qayy.utils.DateUtils;
import cn.qayy.utils.ServletContextUtils;
import cn.qayy.utils.StringUtil;

/***
 *@author wy
 *协议表
 */
@SuppressWarnings("all")
public class PolicyDTO_RE implements Serializable,Uploadable{
	/**
	 * 省份
	 */
    private String province="";
    /***
     * 地市
     */
    private String city="";
    /***
     * 条线
     */
    private String qudaolie="";
    /***
     * 渠道
     */
    private String terminaltype="";
    /***
     * 品种
     */
    private String product="";
    /***
     * 包装
     */
    private String page="";
    /***
     * 客户
     */
    private String client="";
    /***
     * 代表
     */
    private String daibiao="";
    /***
     * 经理
     */
    private String mgr="";
    /***
     * 入货乙方
     */
    private String qsterminal="";
    /***
     * 协议备注
     */
    private String terminal="";
    /***
     * 模式
     */
    private String mode="";
    /***
     * 资金成本
     */
    private String zijingchengben="";
    /***
     * 结算方式
     */
    private String jsmode="";
    /***
     * 开票价
     */
    private String kaipiaojia="";
    /***
     * 1服务费(基础)
     */
    private String tuiguangmoney="";
    /***
     * 3服务费(财务)
     */
    private String fapiaomoney="";
    /***
     * 4服务费(达标)
     */
    private String daibiaomoney="";
    /***
     * 5开发奖励
     */
    private String kaifajianlishixiang="";
    /***
     * 业务员开发奖励
     */
    private String kaifaMgr="";
    
    /***
     * 协议标杆
     */
    private String xieyibiaogang="";
    /***
     * 开发时限
     */
    private String kaifashixiang="";
    /***
     * 协议开始时间
     */
    private String xieyistarttime="";
    /***
     * 协议结束时间
     */
    private String xieyiendtime="";
    /***
     * 协议状态
     */
    private String guihuanriqi="";
    
    /***
     * 开票方案
     */
    private String kaipiaofangshi="";
    /***
     * 收款人
     */
    private String shoukuangren="";
    /***
     * 开户行
     */
    private String kaihuhang="";
    /***
     * 账号
     */
    private String zhanghao="";
    /***
     * 修订标识
     */
    private String isUpdate="E";
    /***
     * id
     */
    private String id="";
    
	public PolicyDTO_RE(String province, String city, String qudaolie, String terminaltype, String product, String page,
			String client, String daibiao, String mgr, String qsterminal, String terminal, String mode,
			String zijingchengben, String jsmode, String kaipiaojia, String tuiguangmoney, String fapiaomoney,
			String daibiaomoney, String kaifajianlishixiang, String xieyibiaogang, String kaifashixiang,
			String xieyistarttime, String xieyiendtime, String kaipiaofangshi, String shoukuangren, String kaihuhang,
			String zhanghao, String id) {
		super();
		this.province = province;
		this.city = city;
		this.qudaolie = qudaolie;
		this.terminaltype = terminaltype;
		this.product = product;
		this.page = page;
		this.client = client;
		this.daibiao = daibiao;
		this.mgr = mgr;
		this.qsterminal = qsterminal;
		this.terminal = terminal;
		this.mode = mode;
		this.zijingchengben = zijingchengben;
		this.jsmode = jsmode;
		this.kaipiaojia = kaipiaojia;
		this.tuiguangmoney = tuiguangmoney;
		this.fapiaomoney = fapiaomoney;
		this.daibiaomoney = daibiaomoney;
		this.kaifajianlishixiang = kaifajianlishixiang;
		this.xieyibiaogang = xieyibiaogang;
		this.kaifashixiang = kaifashixiang;
		this.xieyistarttime = xieyistarttime;
		this.xieyiendtime = xieyiendtime;
		this.kaipiaofangshi = kaipiaofangshi;
		this.shoukuangren = shoukuangren;
		this.kaihuhang = kaihuhang;
		this.zhanghao = zhanghao;
		this.id = id;
	}
	

	public String getGuihuanriqi() {
		return guihuanriqi;
	}
	
	
	public void setGuihuanriqi(String guihuanriqi) {
		this.guihuanriqi = guihuanriqi;
	}

	public String getIsUpdate() {
		return isUpdate;
	}
	
	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}

	public PolicyDTO_RE() {
		super();
	}
	
	/***
     * String key = product+page+qsterminal
     * 唯一标识该this对象
     */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((page == null) ? 0 : page.hashCode());
		result = prime * result + ((product == null) ? 0 : product.hashCode());
		result = prime * result + ((qsterminal == null) ? 0 : qsterminal.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PolicyDTO_RE other = (PolicyDTO_RE) obj;
		if (page == null) {
			if (other.page != null)
				return false;
		} else if (!page.equals(other.page))
			return false;
		if (product == null) {
			if (other.product != null)
				return false;
		} else if (!product.equals(other.product))
			return false;
		if (qsterminal == null) {
			if (other.qsterminal != null)
				return false;
		} else if (!qsterminal.equals(other.qsterminal))
			return false;
		return true;
	}


	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getProvince() {
        return this.province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getQudaolie() {
        return this.qudaolie;
    }

    public void setQudaolie(String qudaolie) {
        this.qudaolie = qudaolie;
    }

    public String getTerminaltype() {
        return this.terminaltype;
    }

    public void setTerminaltype(String terminaltype) {
        this.terminaltype = terminaltype;
    }

    public String getProduct() {
        return this.product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getPage() {
        return this.page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public String getClient() {
        return this.client;
    }

    public void setClient(String client) {
        this.client = client;
    }

    public String getDaibiao() {
        return this.daibiao;
    }

    public void setDaibiao(String daibiao) {
        this.daibiao = daibiao;
    }

    public String getMgr() {
        return this.mgr;
    }

    public void setMgr(String mgr) {
        this.mgr = mgr;
    }

    public String getQsterminal() {
        return this.qsterminal;
    }

    public void setQsterminal(String qsterminal) {
        this.qsterminal = qsterminal;
    }

    public String getTerminal() {
        return this.terminal;
    }

    public void setTerminal(String terminal) {
        this.terminal = terminal;
    }

    public String getMode() {
        return this.mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public String getZijingchengben() {
        return this.zijingchengben;
    }

    public void setZijingchengben(String zijingchengben) {
        this.zijingchengben = zijingchengben;
    }

    public String getJsmode() {
        return this.jsmode;
    }

    public void setJsmode(String jsmode) {
        this.jsmode = jsmode;
    }

    public String getKaipiaojia() {
        return this.kaipiaojia;
    }

    public void setKaipiaojia(String kaipiaojia) {
        this.kaipiaojia = kaipiaojia;
    }

    public String getTuiguangmoney() {
        return this.tuiguangmoney;
    }

    public void setTuiguangmoney(String tuiguangmoney) {
        this.tuiguangmoney = tuiguangmoney;
    }

    public String getFapiaomoney() {
        return this.fapiaomoney;
    }

    public void setFapiaomoney(String fapiaomoney) {
        this.fapiaomoney = fapiaomoney;
    }

    public String getDaibiaomoney() {
        return this.daibiaomoney;
    }

    public void setDaibiaomoney(String daibiaomoney) {
        this.daibiaomoney = daibiaomoney;
    }

    public String getKaifajianlishixiang() {
        return this.kaifajianlishixiang;
    }

    public void setKaifajianlishixiang(String kaifajianlishixiang) {
        this.kaifajianlishixiang = kaifajianlishixiang;
    }

    public String getXieyibiaogang() {
        return this.xieyibiaogang;
    }

    public void setXieyibiaogang(String xieyibiaogang) {
        this.xieyibiaogang = xieyibiaogang;
    }

    public String getKaifashixiang() {
        return this.kaifashixiang;
    }

    public void setKaifashixiang(String kaifashixiang) {
        this.kaifashixiang = kaifashixiang;
    }

    public String getXieyistarttime() {
        return this.xieyistarttime;
    }

    public void setXieyistarttime(String xieyistarttime) {
        this.xieyistarttime = xieyistarttime;
    }

    public String getXieyiendtime() {
        return this.xieyiendtime;
    }

    public void setXieyiendtime(String xieyiendtime) {
        this.xieyiendtime = xieyiendtime;
    }

    public String getKaipiaofangshi() {
        return this.kaipiaofangshi;
    }

    public void setKaipiaofangshi(String kaipiaofangshi) {
        this.kaipiaofangshi = kaipiaofangshi;
    }

    public String getShoukuangren() {
        return this.shoukuangren;
    }

    public void setShoukuangren(String shoukuangren) {
        this.shoukuangren = shoukuangren;
    }

    public String getKaihuhang() {
        return this.kaihuhang;
    }

    public void setKaihuhang(String kaihuhang) {
        this.kaihuhang = kaihuhang;
    }

    public String getZhanghao() {
        return this.zhanghao;
    }

    public void setZhanghao(String zhanghao) {
        this.zhanghao = zhanghao;
    }
    public PolicyDTO_RE(String province, String city, String qudaolie, String terminaltype, String product, String page,
			String client, String daibiao, String mgr, String qsterminal, String terminal, String mode,
			String zijingchengben, String jsmode, String kaipiaojia, String tuiguangmoney, String fapiaomoney,
			String daibiaomoney, String kaifajianlishixiang, String xieyibiaogang, String kaifashixiang,
			String xieyistarttime, String xieyiendtime, String guihuanriqi, String kaipiaofangshi, String shoukuangren,
			String kaihuhang, String zhanghao, String isUpdate, String id) {
		super();
		this.province = province;
		this.city = city;
		this.qudaolie = qudaolie;
		this.terminaltype = terminaltype;
		this.product = product;
		this.page = page;
		this.client = client;
		this.daibiao = daibiao;
		this.mgr = mgr;
		this.qsterminal = qsterminal;
		this.terminal = terminal;
		this.mode = mode;
		this.zijingchengben = zijingchengben;
		this.jsmode = jsmode;
		this.kaipiaojia = kaipiaojia;
		this.tuiguangmoney = tuiguangmoney;
		this.fapiaomoney = fapiaomoney;
		this.daibiaomoney = daibiaomoney;
		this.kaifajianlishixiang = kaifajianlishixiang;
		this.xieyibiaogang = xieyibiaogang;
		this.kaifashixiang = kaifashixiang;
		this.xieyistarttime = xieyistarttime;
		this.xieyiendtime = xieyiendtime;
		this.guihuanriqi = guihuanriqi;
		this.kaipiaofangshi = kaipiaofangshi;
		this.shoukuangren = shoukuangren;
		this.kaihuhang = kaihuhang;
		this.zhanghao = zhanghao;
		this.isUpdate = isUpdate;
		this.id = id;
	}
	@Override
	public Uploadable filter(Map<String, List<Uploadable>> map, Set<Uploadable> set, int num) {
		/** 容纳错误消息的list */
		List<Uploadable> mlist = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);
		/** 容纳正确的，最终用于保存到数据库的数据 **/
		List<Uploadable> list = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);

		/***
		 * 过滤掉所有的空格
		 */
		String province = StringUtil.trimAll(this.getProvince());
		String city = StringUtil.trimAll(this.getCity());
		String qudaolie = StringUtil.trimAll(this.getQudaolie());
		String terminaltype = StringUtil.trimAll(this.getTerminaltype());
		String product = StringUtil.trimAll(this.getProduct());
		String page = StringUtil.trimAll(this.getPage());
		String client = StringUtil.trimAll(this.getClient());
		String daibiao = StringUtil.trimAll(this.getDaibiao());
		String mgr = StringUtil.trimAll(this.getMgr());
		String qsterminal = StringUtil.trimAll(this.getQsterminal());
		String terminal = StringUtil.trimAll(this.getTerminal());
		String mode = StringUtil.trimAll(this.getMode());
		String zijingchengben = StringUtil.trimAll(this.getZijingchengben());
		String jsmode = StringUtil.trimAll(this.getJsmode());
		String kaipiaojia = StringUtil.trimAll(this.getKaipiaojia());
		String tuiguangmoney = StringUtil.trimAll(this.getTuiguangmoney());
		String fapiaomoney = StringUtil.trimAll(this.getFapiaomoney());
		String daibiaomoney = StringUtil.trimAll(this.getDaibiaomoney());
		String kaifajianlishixiang = StringUtil.trimAll(this.getKaifajianlishixiang());
		String kaifaMgr = StringUtil.trimAll(this.getKaifaMgr());
		String xieyibiaogang = StringUtil.trimAll(this.getXieyibiaogang());
		String kaifashixiang = StringUtil.trimAll(this.getKaifashixiang());
		String xieyistarttime = StringUtil.trimAll(this.getXieyistarttime());
		String xieyiendtime = StringUtil.trimAll(this.getXieyiendtime());
		String guihuanriqi = StringUtil.trimAll(this.getGuihuanriqi());
		String kaipiaofangshi = StringUtil.trimAll(this.getKaipiaofangshi());
		String shoukuangren = StringUtil.trimAll(this.getShoukuangren());
		String kaihuhang = StringUtil.trimAll(this.getKaihuhang());
		String zhanghao = StringUtil.trimAll(this.getZhanghao());
		String isUpdate = StringUtil.trimAll(this.getIsUpdate());
		String id = StringUtil.trimAll(this.getId());

		/**
		 * 判断是否导入的模板是正确的模板
		 */
		if (num == 1) {
			if (!CollectionConstant.policy_mb.get(0).startsWith(province) 
					|| !CollectionConstant.policy_mb.get(1).startsWith(city)
					|| !CollectionConstant.policy_mb.get(2).startsWith(qudaolie)
					|| !CollectionConstant.policy_mb.get(3).startsWith(terminaltype)
					|| !CollectionConstant.policy_mb.get(4).startsWith(product)
					|| !CollectionConstant.policy_mb.get(5).startsWith(page)
					|| !CollectionConstant.policy_mb.get(6).startsWith(client)
					|| !CollectionConstant.policy_mb.get(7).startsWith(daibiao)
					|| !CollectionConstant.policy_mb.get(8).startsWith(mgr)
					|| !CollectionConstant.policy_mb.get(9).startsWith(qsterminal)
					|| !CollectionConstant.policy_mb.get(10).startsWith(terminal)
					|| !CollectionConstant.policy_mb.get(11).startsWith(mode)
					|| !CollectionConstant.policy_mb.get(12).startsWith(zijingchengben)
					|| !CollectionConstant.policy_mb.get(13).startsWith(jsmode)
					|| !CollectionConstant.policy_mb.get(14).startsWith(kaipiaojia)
					|| !CollectionConstant.policy_mb.get(15).startsWith(tuiguangmoney)
					|| !CollectionConstant.policy_mb.get(16).startsWith(fapiaomoney)
					|| !CollectionConstant.policy_mb.get(17).startsWith(daibiaomoney)
					|| !CollectionConstant.policy_mb.get(18).startsWith(kaifajianlishixiang)
					|| !CollectionConstant.policy_mb.get(19).startsWith(kaifaMgr)
					|| !CollectionConstant.policy_mb.get(20).startsWith(xieyibiaogang)
					|| !CollectionConstant.policy_mb.get(21).startsWith(kaifashixiang)
					|| !CollectionConstant.policy_mb.get(22).startsWith(xieyistarttime)
					|| !CollectionConstant.policy_mb.get(23).startsWith(xieyiendtime)
					|| !CollectionConstant.policy_mb.get(24).startsWith(guihuanriqi)
					|| !CollectionConstant.policy_mb.get(25).startsWith(kaipiaofangshi)
					|| !CollectionConstant.policy_mb.get(26).startsWith(shoukuangren)
					|| !CollectionConstant.policy_mb.get(27).startsWith(kaihuhang)
					|| !CollectionConstant.policy_mb.get(28).startsWith(zhanghao)
					|| !CollectionConstant.policy_mb.get(29).startsWith(isUpdate)
					|| !CollectionConstant.policy_mb.get(30).startsWith(id)) {
				MsgInfo msg = new MsgInfo(Constant.ERROR_MB, Constant.ERROR_MB, Constant.ERROR_MB,
						Constant.ERROR_NUM + num);
				mlist.add(msg);
				map.put("stop", mlist);
				return null;
			}
		} else {
			/***
			 * 获取项目上下文的共享数据
			 */
			ServletContext servletContext = ServletContextUtils.getServletContext();
			/**省份**/
			Set<String> provinces = (HashSet<String>) servletContext.getAttribute("provinces");
			/**地市**/
			Set<String> citys = (HashSet<String>) servletContext.getAttribute("citys");
			/**协议keys**/
			HashSet<String> policyKeys = ((HashSet<String>) servletContext.getAttribute("policyKeys"));
			
			if("E".equals(isUpdate)) {
				if(StringUtil.isBlank(id)) {
					MsgInfo msg = new MsgInfo(isUpdate,"修订标识有误或id有误","修订标识为E或空白时，id不能为空。id为空白时，修订标识只能是N",Constant.ERROR_NUM+num);
					mlist.add(msg);
				}
			}
			
			/***
			 * 数据合格性校验
			 */
			if (!CollectionConstant.cuFlags.contains(isUpdate)) {
				MsgInfo msg = new MsgInfo(isUpdate, "修订标识", CollectionConstant.cudFlags.toString(),
						Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 省份参考【基础库】的省份
			 */
			if (!provinces.contains(province)) {
				MsgInfo msg = new MsgInfo(province, "省份", Constant.BASIC_DATA, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 参考【基础库】的地市
			 */
			if (!citys.contains(city)) {
				MsgInfo msg = new MsgInfo(city, "地市", Constant.BASIC_DATA, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 判断条线
			 */
			if(!CollectionConstant.txs.contains(qudaolie)) {
				MsgInfo msg = new MsgInfo(qudaolie, "条线", CollectionConstant.txs.toString(),Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 判断渠道
			 */
			if(!CollectionConstant.qudaos.contains(terminaltype)) {
				MsgInfo msg = new MsgInfo(terminaltype, "渠道", CollectionConstant.qudaos.toString(),Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 判断品种
			 */
			if (!CollectionConstant.products.contains(product)) {
				MsgInfo msg = new MsgInfo(product, "品种", CollectionConstant.products.toString(),
						Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 判断包装
			 */
			if (!CollectionConstant.packs.contains(page)) {
				MsgInfo msg = new MsgInfo(page, "包装", CollectionConstant.packs.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			
			/***
			 * 客户
			 */
			if(StringUtil.isBlank(client)) {
				MsgInfo msg = new MsgInfo(client, "客户", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 代表
			 */
			if(StringUtil.isBlank(daibiao)) {
				MsgInfo msg = new MsgInfo(daibiao, "代表", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 经理
			 */
			if(StringUtil.isBlank(mgr)) {
				MsgInfo msg = new MsgInfo(mgr, "经理", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 入货乙方
			 */
			if(StringUtil.isBlank(qsterminal)) {
				MsgInfo msg = new MsgInfo(qsterminal, "入货乙方", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 模式
			 */
			if(!CollectionConstant.modes.contains(mode)) {
				MsgInfo msg = new MsgInfo(mode, "模式", CollectionConstant.modes.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 资金成本
			 */
			if(StringUtil.isNotBlank(zijingchengben)) {
				if(StringUtil.parseFloat(zijingchengben)==null) {
					MsgInfo msg = new MsgInfo(zijingchengben, "资金成本", Constant.NUMBER, Constant.ERROR_NUM + num);
					mlist.add(msg);
				}
			}
			/**
			 * 结算方式
			 */
			if(!CollectionConstant.jsmodes.contains(jsmode)) {
				MsgInfo msg = new MsgInfo(jsmode, "结算方式", CollectionConstant.jsmodes.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 开票价
			 */
			if (StringUtil.parseFloat(kaipiaojia) == null) {
				MsgInfo msg = new MsgInfo(kaipiaojia, "开票价", Constant.NUMBER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 1服务费(基础)
			 */
			if (StringUtil.parseFloat(tuiguangmoney) == null) {
				MsgInfo msg = new MsgInfo(tuiguangmoney, "1服务费(基础)", Constant.NUMBER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 3服务费(财务)
			 */
			if (StringUtil.parseFloat(fapiaomoney) == null) {
				MsgInfo msg = new MsgInfo(fapiaomoney, "3服务费(财务)", Constant.NUMBER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 4服务费(达标)
			 */
			if (StringUtil.parseFloat(daibiaomoney) == null) {
				MsgInfo msg = new MsgInfo(daibiaomoney, "4服务费(达标)", Constant.NUMBER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 5开发奖励
			 */
			if (StringUtil.parseFloat(kaifajianlishixiang) == null) {
				MsgInfo msg = new MsgInfo(kaifajianlishixiang, "5开发奖励", Constant.NUMBER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 业务员开发奖励
			 */
			if(StringUtil.isNotBlank(kaifaMgr)) {
				if (StringUtil.parseFloat(kaifaMgr) == null) {
					MsgInfo msg = new MsgInfo(kaifaMgr, "业务员开发奖励", Constant.NUMBER, Constant.ERROR_NUM + num);
					mlist.add(msg);
				}
			}
			/**
			 * 协议标杆
			 */
			if (StringUtil.parseInt(xieyibiaogang) == null) {
				MsgInfo msg = new MsgInfo(xieyibiaogang, "协议标杆", Constant.INTEGER, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			
			/**
			 * 判断日期
			 */
			if(DateUtils.parseDate(xieyistarttime) == null) {
				MsgInfo msg = new MsgInfo(xieyistarttime, "开始时间", Constant.DATE_FORMAT, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			
			if(DateUtils.parseDate(xieyiendtime) == null) {
				MsgInfo msg = new MsgInfo(xieyiendtime, "结束时间", Constant.DATE_FORMAT, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 协议状态
			 */
			if(!CollectionConstant.policyStatus.contains(guihuanriqi)) {
				MsgInfo msg = new MsgInfo(guihuanriqi, "协议状态", CollectionConstant.policyStatus.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/**
			 * 票据方案
			 */
			if(!CollectionConstant.ticket_plan.contains(kaipiaofangshi)) {
				MsgInfo msg = new MsgInfo(kaipiaofangshi, "票据方案", CollectionConstant.ticket_plan.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 收款人
			 */
			if(StringUtil.isBlank(shoukuangren)) {
				MsgInfo msg = new MsgInfo(shoukuangren, "收款人", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 开户行
			 */
			if(StringUtil.isBlank(kaihuhang)) {
				MsgInfo msg = new MsgInfo(kaihuhang, "开户行", Constant.NOT_BLANK_MSG, Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 账号
			 */
			if(zhanghao == null) {
				MsgInfo msg = new MsgInfo(zhanghao, "账号", CollectionConstant.bank_card.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			} else if(!zhanghao.contains("银行卡")){
				MsgInfo msg = new MsgInfo(zhanghao, "账号", CollectionConstant.bank_card.toString(), Constant.ERROR_NUM + num);
				mlist.add(msg);
			}
			/***
			 * 判断是否在数据库中存在，排除重复项的可能，目前的判断方式：品种、包装、入货乙方、协议开始时间，协议结束时间，来判断重复项的
			 * 
			 */
			//空白行不允许添加，也无须进行重复项判断
			if(StringUtil.isNotBlank(this.getClient())
					&&StringUtil.isNotBlank(this.getProduct())
					&&DateUtils.parseDate(this.getXieyistarttime()) != null
					&&DateUtils.parseDate(this.getXieyiendtime()) != null) {
				String key = product+","+page+","+qsterminal;
				Iterator<String> iterator = policyKeys.iterator();
				while(iterator.hasNext()) {
					String next = iterator.next();
					if(next.contains(key)) {
						SimpleDateFormat SDF = new SimpleDateFormat("yyyy/MM/dd");
						try {
							Date ds = SDF.parse(xieyistarttime);
							Date de = SDF.parse(xieyiendtime);
							
							String pz = next.split(",")[0];//系统里的品种
							String bz = next.split(",")[1];//系统里的包装
							String terninal = next.split(",")[2];//系统里的入货乙方
							Date d1 = SDF.parse(next.split(",")[3]);//系统开始
							Date d2 = SDF.parse(next.split(",")[4]);//系统结束
							boolean ok = false;
							
							if(product.equals(pz) &&
									page.equals(bz) &&
									qsterminal.equals(terninal) &&
									ds.getTime()==d1.getTime() && de.getTime()==d2.getTime() 
									&& "N".equals(isUpdate)) {
								ok = true;
							}
							if(product.equals(pz) &&
									page.equals(bz) &&
									qsterminal.equals(terninal)) {
								//上传的是否和系统的交集
								if(!ok) {
									if(ds.getTime()>d1.getTime() && ds.getTime()<d2.getTime()) {
										ok = true;
									}
								}
								if(!ok) {
									if(de.getTime()>d1.getTime() && de.getTime()<d2.getTime()) {
										ok = true;
									}
								}
								//系统的是否和上传的交集
								if(!ok) {
									if(d1.getTime()>ds.getTime() && d1.getTime()<de.getTime()) {
										ok = true;
									}
								}
								if(!ok) {
									if(d2.getTime()>ds.getTime() && d2.getTime()<de.getTime()) {
										ok = true;
									}
								}
							}
							
							if(ok) {
								MsgInfo msg = new MsgInfo(key,Constant.REPEATABLE,"对应了多个协议，请检查",Constant.ERROR_NUM+num);
								mlist.add(msg);
								break;
							}
						} catch (ParseException e) {
							break;
						}
					}
				}
			}
			
			/*** 把验证通过的合格数据返回 **/
			this.setAll(province, city, qudaolie, terminaltype, 
					product, page, client,daibiao,mgr,qsterminal,
					terminal,mode,zijingchengben,jsmode,kaipiaojia,tuiguangmoney,
					fapiaomoney,daibiaomoney,kaifajianlishixiang,kaifaMgr,xieyibiaogang,kaifashixiang,
					DateUtils.parseDate(xieyistarttime),DateUtils.parseDate(xieyiendtime),guihuanriqi,kaipiaofangshi,shoukuangren,
					kaihuhang,zhanghao,
					isUpdate, id);
			
			//空白行不允许添加，也无须进行重复项判断
			if(StringUtil.isNotBlank(this.getClient())
					&&StringUtil.isNotBlank(this.getProduct())
					&&DateUtils.parseDate(this.getXieyistarttime()) != null
					&&DateUtils.parseDate(this.getXieyiendtime()) != null) {
				//循环判断Excel里的数据是否存在重复项
				Iterator<Uploadable> it = set.iterator();
				while(it.hasNext()) {
					PolicyDTO_RE nextDto = (PolicyDTO_RE)it.next();
					if(nextDto.getProduct().equals(this.getProduct()) && 
							nextDto.getPage().equals(this.getPage()) &&
							nextDto.getQsterminal().equals(this.getQsterminal())) {
						SimpleDateFormat SDF = new SimpleDateFormat("yyyy/MM/dd");
						try {
							Date thisD1 = SDF.parse(this.getXieyistarttime());//当前的开始时间
							Date thisD2 = SDF.parse(this.getXieyiendtime());//当前的结束时间
							Date d1 = SDF.parse(nextDto.getXieyistarttime());//set内存中的开始时间
							Date d2 = SDF.parse(nextDto.getXieyiendtime());//set内存中的结束时间
							boolean ok = false;
							
							if(thisD1.getTime()==d1.getTime() && thisD2.getTime()==d2.getTime()) {
								ok = true;
							}
							if(!ok) {
								if(thisD1.getTime()>d1.getTime() && thisD1.getTime()<d2.getTime()) {
									ok = true;
								}
							}
							if(!ok) {
								if(thisD2.getTime()>d1.getTime() && thisD2.getTime()<d2.getTime()) {
									ok = true;
								}
							}
							if(!ok) {
								if(d1.getTime()>thisD1.getTime() && d1.getTime()<thisD2.getTime()) {
									ok = true;
								}
							}
							if(!ok) {
								if(d2.getTime()>thisD1.getTime() && d2.getTime()<thisD2.getTime()) {
									ok = true;
								}
							}
							if(ok) {
								MsgInfo msg = new MsgInfo("Excel文件本身：",Constant.REPEATABLE,"对应了多个协议，请检查",Constant.ERROR_NUM+num);
								mlist.add(msg);
								break;
							}
						} catch (ParseException e) {
						}
					}
				}
				set.add(this);
			}
			/***
			 * 返回处理后的结果数据
			 */
			if (!mlist.isEmpty()) {
				map.put("fail" + num, mlist);
			} 
			return this;
		}
		return null;
	}
	public void setAll(String province, String city, String qudaolie, String terminaltype,
			String product, String page,
			String client, String daibiao, String mgr, String qsterminal, 
			String terminal, String mode,
			String zijingchengben, String jsmode, String kaipiaojia, String tuiguangmoney, 
			String fapiaomoney,
			String daibiaomoney, String kaifajianlishixiang,String kaifaMgr, String xieyibiaogang, 
			String kaifashixiang,
			String xieyistarttime, String xieyiendtime, String guihuanriqi, 
			String kaipiaofangshi, String shoukuangren,
			String kaihuhang, String zhanghao, String isUpdate, String id) {
		this.province = province;
		this.city = city;
		this.qudaolie = qudaolie;
		this.terminaltype = terminaltype;
		this.product = product;
		this.page = page;
		this.client = client;
		this.daibiao = daibiao;
		this.mgr = mgr;
		this.qsterminal = qsterminal;
		this.terminal = terminal;
		this.mode = mode;
		this.zijingchengben = zijingchengben;
		this.jsmode = jsmode;
		this.kaipiaojia = kaipiaojia;
		this.tuiguangmoney = tuiguangmoney;
		this.fapiaomoney = fapiaomoney;
		this.daibiaomoney = daibiaomoney;
		this.kaifajianlishixiang = kaifajianlishixiang;
		this.kaifaMgr = kaifaMgr;
		this.xieyibiaogang = xieyibiaogang;
		this.kaifashixiang = kaifashixiang;
		this.xieyistarttime = xieyistarttime;
		this.xieyiendtime = xieyiendtime;
		this.guihuanriqi = guihuanriqi;
		this.kaipiaofangshi = kaipiaofangshi;
		this.shoukuangren = shoukuangren;
		this.kaihuhang = kaihuhang;
		this.zhanghao = zhanghao;
		this.isUpdate = isUpdate;
		this.id = id;
	}
	@Override
	public String flag() {
		return this.isUpdate;
	}
	public String getKaifaMgr() {
		return kaifaMgr;
	}
	public void setKaifaMgr(String kaifaMgr) {
		this.kaifaMgr = kaifaMgr;
	}

}
